package com.lyz.util;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author zhangdi
 *
 * @date 2014-5-4
 * @class StringUtil.java
 */
public class StringUtil {

	/**
	 * @param args
	 * @date 2014-5-4
	 * @return void
	 */
	public static void main(String[] args) {
		List<String> lists = new ArrayList<String>();
		lists.add("1");
		lists.add("2");
		lists.add("3");
		lists.add("4");
		System.out.println(getList(getString(lists, "%"),"%"));

	}
	
	/**
	 * get string separated by sep
	 * @param lists lists of String
	 * @param sep  String separator
	 * @return
	 * @date 2014-5-4
	 * @return String
	 */
	public static String getString(List<String> lists,String sep) {		
		if(lists == null || lists.size() == 0) {
			return null;
		}
		StringBuffer result = new StringBuffer();
		for(String str : lists) {
			result.append(str + sep);
		}
		return result.toString().substring(0, result.toString().length()-sep.length());
	}
	
	/**
	 * get list of String from strs separated by sep
	 * @param strs
	 * @param sep
	 * @return
	 * @date 2014-5-4
	 * @return List<String>
	 */
	public static List<String> getList(String strs,String sep) {
		if(strs == null || strs.equals("")) {
			return null;
		}
		List<String> result = new ArrayList<String>();
		for(String str : strs.split(sep)) {
			result.add(str);
		}
		return result;
	}
	
	/**
	 * 
	 * @param value
	 * @param spliter
	 * @return
	 * @date 2014-5-5
	 * @return String[]
	 */
	public static String[] parseToStrings(String value,String spliter) {
		String[] values = value.split(spliter);
		return values;
	}

}
